package com.appspot.zcmjqm.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.appspot.zcmjqm.app.model.quote.ConsultQuote;
import com.appspot.zcmjqm.service.ConsultService;

@Controller
@RequestMapping("/consult")
public class ConsultControllerWebMVCImpl implements ConsultController {
	
	@Autowired
	private ConsultService consultService;

	@RequestMapping("/display.do")
	public ModelAndView displayConsult(@RequestParam String consultKey) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("consult", consultService.getById(consultKey));
		mav.setViewName("consulting");
		return mav;
	}

	@RequestMapping("/list.do")
	public ModelAndView displayConsults(@RequestParam String categoryKey) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("consults", consultService.getByCategory(categoryKey));
		mav.setViewName("consultings");
		return mav;
	}
	
	@RequestMapping("/dispalyquote.do")
	public ModelAndView displayQuote(@RequestParam String consultKey) {
		ModelAndView mav = new ModelAndView();
		ConsultQuote consultQuote = new ConsultQuote();
		consultQuote.setConsult(consultService.getById(consultKey));
		mav.addObject("consultQuote", consultQuote);
		mav.setViewName("consultingQuote");
		return mav;
	}
	
	@RequestMapping("/quote.do")
	public ModelAndView newConsultQuote(ConsultQuote consultQuote) {
		ModelAndView mav = new ModelAndView();
		consultService.saveQuote(consultQuote);
		mav.setViewName("redirect:/home/show.do");
		return mav;
	}

	public void setConsultService(ConsultService consultService) {
		this.consultService = consultService;
	}
	
}